package com.yongjie.springbootlogin.controller;

import com.yongjie.springbootlogin.entity.Billing;
import com.yongjie.springbootlogin.entity.Registration;
import com.yongjie.springbootlogin.service.Interface.BillingService;
import com.yongjie.springbootlogin.service.Interface.RegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * 医生开单
 */
@Controller
public class BillingController {
    @Autowired
    RegistrationService registrationService;
    @Autowired
    BillingService billingService;
    @RequestMapping(value = "/Billing")
    public String Billing(Model model,  String id ,String pai_name){
        //查询病人信息
        Registration reg = registrationService.getRegfindById(id);
        model.addAttribute("reg",reg);
        //名字
        model.addAttribute("name",pai_name);
        model.addAttribute("rid",id);
        return "Billing/billing";
    }
    /**
     * 添加数据
     */
    @RequestMapping(value = "/addBilling")
    public String addBilling(Billing billing,
                             @RequestParam("rid")String rid,
                             HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        billingService.addBilling(billing);

        System.out.println("---"+rid);
        //更改病人数据状态
        int count = registrationService.delreg(rid);
        if(count>0){
            response.getWriter().write("<script>  alert('下单成功')</script>");
        }else{
            response.getWriter().write("<script>  alert('下单失败')</script>");
        }

        return "Billing/billing";
    }
}

